home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / desktop / spinner.zip / SPINNER.C < prev    next >
C/C++ Source or Header  |  1991-10-10  |  4KB  |  158 lines

  1. //
  2. // SPINNER - spinning rainbow SPX library
  3. //
  4. // Version 1.0 10/04/91 Copyright (C) 91 Lantern Corp.
  5. // Author: Edward Hutchins
  6. // Revisions:
  7. // 10/09/91 moved from smplspx to spinner (prettied up) - Ed.
  8. //
  9.  
  10. #include "spinner.h"
  11.  
  12. //
  13. // globals
  14. //
  15.  
  16. GLOBAL HANDLE       hLibInst;                           // current instance
  17. GLOBAL INT          nColorCnt;                          // number of colors
  18. GLOBAL BOOL         bEnabled;                           // SPX enable switch
  19. GLOBAL TRI          triBlank;                           // blank screen first
  20. GLOBAL TRI          triSpin;                            // spin it up!
  21. GLOBAL TRI          triSolid;                           // fill it in!
  22. GLOBAL CHAR         szAppName[] = "Screen Peace";       // saver app name
  23. GLOBAL CHAR         szSaverName[] = "Spinner";          // SPX name
  24. GLOBAL CHAR         szProfColor[] = "Spinner Colors";   // profiler key
  25. GLOBAL CHAR         szProfEnabled[] = "Spinner On";     // profiler key
  26. GLOBAL CHAR         szProfBlank[] = "Spinner Blank";    // profiler key
  27. GLOBAL CHAR         szProfSpin[] = "Spinner Spin";      // profiler key
  28. GLOBAL CHAR         szProfSolid[] = "Spinner Solid";    // profiler key
  29.  
  30. //
  31. // GetProfileTri - get a tri-state variable from the profile
  32. //
  33.  
  34. TRI NEAR PASCAL GetProfileTri( LPSTR lpszKey )
  35. {
  36.     GLOBAL CHAR         szBuff[64];
  37.  
  38.     GetProfileString( szAppName, lpszKey, "u", szBuff, sizeof(szBuff) );
  39.     switch (szBuff[0])
  40.     {
  41.     case 'N': case 'n':
  42.         return( TRI_FALSE );
  43.     case 'Y': case 'y':
  44.         return( TRI_TRUE );
  45.     default:
  46.         return( TRI_UNSET );
  47.     }
  48. }
  49.  
  50. //
  51. // WriteProfileTri - write a tri-state variable to the profile
  52. //
  53.  
  54. BOOL NEAR PASCAL WriteProfileTri( LPSTR lpszKey, TRI tri )
  55. {
  56.     switch (tri)
  57.     {
  58.     case TRI_FALSE:
  59.         return( WriteProfileString( szAppName, lpszKey, "n" ) );
  60.     case TRI_TRUE:
  61.         return( WriteProfileString( szAppName, lpszKey, "y" ) );
  62.     default:
  63.         return( WriteProfileString( szAppName, lpszKey, "u" ) );
  64.     }
  65. }
  66.  
  67. //
  68. // WriteProfileInt - write an integer to the profile
  69. //
  70.  
  71. BOOL NEAR PASCAL WriteProfileInt( LPSTR lpszKey, INT nVal )
  72. {
  73.     GLOBAL CHAR         szBuff[64];
  74.  
  75.     wsprintf( szBuff, "%u", nVal );
  76.     return( WriteProfileString( szAppName, lpszKey, szBuff ) );
  77. }
  78.  
  79. //
  80. // LibMain - initialize the local data segment
  81. //
  82.  
  83. BOOL FAR PASCAL EXPORT LibMain( HANDLE hInstance, WORD wDataSeg,
  84.                                 WORD wHeapSize, LPSTR szCmdLine )
  85. {
  86.     hLibInst = hInstance;
  87.     nColorCnt = GetProfileInt( szAppName, szProfColor, PALETTE_SIZE );
  88.     bEnabled = GetProfileTri( szProfEnabled );
  89.     triBlank = GetProfileTri( szProfBlank );
  90.     triSpin = GetProfileTri( szProfSpin );
  91.     triSolid = GetProfileTri( szProfSolid );
  92.     UnlockData( 0 );
  93.     return( TRUE );
  94. }
  95.  
  96. //
  97. // WEP - Windows Exit Procedure, clean up resources
  98. //
  99.  
  100. VOID FAR PASCAL EXPORT WEP( BOOL bSystemExit )
  101. {
  102. }
  103.  
  104. //
  105. // SaverInit - register with Screen Peace
  106. //
  107.  
  108. LPSTR FAR PASCAL EXPORT SaverInit( LPBOOL lpbEnabled )
  109. {
  110.     *lpbEnabled = bEnabled;
  111.     return( szSaverName );
  112. }
  113.  
  114. //
  115. // SaverDlgProc - dialog proc for user customization
  116. //
  117.  
  118. BOOL FAR PASCAL EXPORT SaverDlgProc( HWND hdlg, WORD mess, WORD wP, LONG lP )
  119. {
  120.     switch (mess)
  121.     {
  122.     case WM_INITDIALOG:
  123.         SetDlgItemInt( hdlg, IDD_S_COLOR, nColorCnt, FALSE );
  124.         SendDlgItemMessage( hdlg, IDD_S_ENABLE, BM_SETCHECK, bEnabled, 0 );
  125.         SendDlgItemMessage( hdlg, IDD_S_BLANK, BM_SETCHECK, triBlank, 0 );
  126.         SendDlgItemMessage( hdlg, IDD_S_SPIN, BM_SETCHECK, triSpin, 0 );
  127.         SendDlgItemMessage( hdlg, IDD_S_SOLID, BM_SETCHECK, triSolid, 0 );
  128.         return( TRUE );
  129.  
  130.     case WM_COMMAND:
  131.         switch (wP)
  132.         {
  133.         case IDOK:
  134.             nColorCnt = GetDlgItemInt( hdlg, IDD_S_COLOR, NULL, FALSE );
  135.             bEnabled = (BOOL)SendDlgItemMessage( hdlg, IDD_S_ENABLE, BM_GETCHECK, 0, 0 );
  136.             triBlank = (TRI)SendDlgItemMessage( hdlg, IDD_S_BLANK, BM_GETCHECK, 0, 0 );
  137.             triSpin = (TRI)SendDlgItemMessage( hdlg, IDD_S_SPIN, BM_GETCHECK, 0, 0 );
  138.             triSolid = (TRI)SendDlgItemMessage( hdlg, IDD_S_SOLID, BM_GETCHECK, 0, 0 );
  139.             WriteProfileTri( szProfEnabled, bEnabled );
  140.             if (bEnabled)
  141.             {
  142.                 WriteProfileInt( szProfColor, nColorCnt );
  143.                 WriteProfileTri( szProfBlank, triBlank );
  144.                 WriteProfileTri( szProfSpin, triSpin );
  145.                 WriteProfileTri( szProfSolid, triSolid );
  146.             }
  147.             EndDialog( hdlg, TRUE );
  148.             return( TRUE );
  149.  
  150.         case IDCANCEL:
  151.             EndDialog( hdlg, FALSE );
  152.             return( TRUE );
  153.         }
  154.         break;
  155.     }
  156.     return( FALSE );
  157. }
  158.